﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using DataAccess.Classes;

namespace Webmau.Admin.Control
{
    public partial class DiaDiem_CapNhat : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["ID"] ?? "";
            if (id != "")
            {
                DiaDiem1 dd = DiaDiem1.LayID(int.Parse(id));
                txtID.Text = dd.ID.ToString();
                txtDiaDiem.Text = dd.TenDiaDiem;
                txtThongTin.Text = dd.ThongTin;
                if (dd.TinhTrang == Convert.ToBoolean("True".ToString()))
                {
                    cbHienThi.Checked = true;
                }
                if (dd.TinhTrang == Convert.ToBoolean("False".ToString()))
                {
                    cbHienThi.Checked = false;
                }
            }

        }
        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            try
            {
                DiaDiem1 diadiem = DuLieu();
                DiaDiem1.CapNhat(diadiem);
                lbThongBao.Text = "OK";
            }
            catch
            {
                lbThongBao.Text = "That bai";
            }
        }

        private DiaDiem1 DuLieu()
        {
            string id = Request.QueryString["ID"];
            DiaDiem1 diadiem = DiaDiem1.LayID(int.Parse(id));
            diadiem.TenDiaDiem = txtDiaDiem.Text.ToString();
            diadiem.ThongTin = txtThongTin.Text.ToString();
            if (cbHienThi.Checked == true)
            {
                diadiem.TinhTrang = Convert.ToBoolean("True".ToString());
            }
            if (cbHienThi.Checked == false)
            {
                diadiem.TinhTrang = Convert.ToBoolean("False".ToString());
            }
            return diadiem;
        }
    }
}